package com.mnc.util;

import java.io.Serializable;

import org.springframework.stereotype.Service;

@Service
public class PageUtil implements Serializable{
		/**
	 * 
	 */
	private static final long serialVersionUID = -8915131683200512149L;
		private int currentPage=1;
		private int allPages;
		private boolean prePage = false;
		private boolean nextPage = false;
		private int[] fontPages=new int[5];
		private String pageURL;
		public int getCurrentPage() {
			return currentPage;
		}
		public void setCurrentPage(int currentPage) {
			this.currentPage = currentPage;
		}
		public int getAllPages() {
			return allPages;
		}
		public void setAllPages(int allPages) {
			this.allPages = allPages;
		}
		public boolean isPrePage() {
			return prePage;
		}
		public void setPrePage(boolean prePage) {
			this.prePage = prePage;
		}
		public boolean isNextPage() {
			return nextPage;
		}
		public void setNextPage(boolean nextPage) {
			this.nextPage = nextPage;
		}
		public static long getSerialversionuid() {
			return serialVersionUID;
		}
		public int[] getFontPages() {
			return fontPages;
		}
		public void setFontPages(int[] fontPages) {
			this.fontPages = fontPages;
		}
		public String getPageURL() {
			return pageURL;
		}
		public void setPageURL(String pageURL) {
			this.pageURL = pageURL;
		}
		public void buildPage(int total,String pageURL,int curPage) {
			int pages=1;
			if (total>0) {
				pages=total/Helper.PAGE_SIZE;
				pages+=total%Helper.PAGE_SIZE!=0?1:0;
				this.setAllPages(pages);
			}
			if (curPage>1) {
				this.setPrePage(true);
			}
			if (curPage<pages) {
				this.setNextPage(true);
			}
			this.setPageURL(pageURL);
			this.setCurrentPage(curPage);
			if (pages>=fontPages.length) {
				for(int i=0;i<fontPages.length;i++) {
					this.fontPages[i]=i+1;
				}
			}else {
				this.fontPages=new int[pages];
				for(int i=0;i<fontPages.length;i++) {
					this.fontPages[i]=i+1;
				}
			}
		}
}
